﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;

namespace GeniusWebApplication.Silveright
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class UpLoadService
    {
        [OperationContract]
        public void ActionUpload(string fileName, byte[] fileContext)
        {
            string uploadFolder = System.Web.Hosting.HostingEnvironment.MapPath("~/uploaded/media");


            if (!System.IO.Directory.Exists(uploadFolder))
            {
                System.IO.Directory.CreateDirectory(uploadFolder);
            }


            System.IO.FileMode fileMode;

            if (!System.IO.File.Exists(uploadFolder + @"\" + fileName))
            {
                fileMode = System.IO.FileMode.Create;
            }

          
            else
            {
                fileMode = System.IO.FileMode.Append;
            }
           

            using (System.IO.FileStream fs = new System.IO.FileStream(uploadFolder + @"\" + fileName, fileMode, System.IO.FileAccess.Write))
            {

                fs.Write(fileContext, 0, fileContext.Length);
            }
        }

        // 在此处添加更多操作并使用 [OperationContract] 标记它们
    }
}
